<template>
  <div>
    <div class="flexrowbetween flexwrapper" style="align-items:flex-start">
      <div class="iconbox flexcenter commhover blackbg" @click="resetQuery">
        <i class="el-icon-refresh f-20" :class="{'rotate':isrefresh}"></i>
      </div>
      <div>
        <el-form
          :model="queryParams"
          ref="queryForm"
          size="small"
          :inline="true"
          label-width="0"
        >
          <el-form-item prop="name">
            <el-input class="searchinput"
              v-model="queryParams.name"
              placeholder="请输入活动名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item class="mr_0">
            <el-dropdown trigger="click">
                <el-button size="mini" class="nor_border plr_9">
                  <svg-icon class-name="f-14" icon-class="listicon" />
                  <i class="el-icon-caret-bottom el-icon--right"></i>
                    <!-- <i class="el-icon-s-fold f-14"></i> -->
                </el-button>
                <el-dropdown-menu slot="dropdown">
                    <div class="dropbody">
                      <el-checkbox-group v-model="checkedOption" class="flexcolumn" @change="changeSelect">
                        <el-checkbox v-for="(item,index) in selectoptions" :label="item.label" :key="index" class="m_5">{{item.label}}</el-checkbox>
                      </el-checkbox-group>
                    </div>
                </el-dropdown-menu>
            </el-dropdown>
          </el-form-item>
          <el-form-item>
            <el-dropdown trigger="click" @command="handleCommand">
                <el-button size="mini" class="nol_border plr_9">
                  <svg-icon class-name="f-14" icon-class="export" />
                  <i class="el-icon-caret-bottom el-icon--right"></i>
                </el-button>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item v-for="(item,index) in exportlist" :key="index" :command="item.id">{{item.name}}</el-dropdown-item>
                </el-dropdown-menu>
            </el-dropdown>
          </el-form-item>
          <el-form-item>
            <el-button class="f-14"
              type=""
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
            ></el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <el-table
        v-loading="loading"
        :data="list"
        border
        ref="tablelayout"
        class="commtable"
      >
        <el-table-column label="" prop="search_engine" width="80" align="center">
          <template slot-scope="scope">
            <el-popover
                placement="bottom-start"
                width="120"
                trigger="hover">
                <img src="@/assets/images/icon1.png" class="imgbox"/>
                <img src="@/assets/images/icon1.png" class="imgmini" slot="reference" />
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column label="平台" prop="platName" width="120" align="center" v-if="activeOption.includes('平台')">
          <template slot-scope="scope">
            {{ scope.row.platName }} 智选评选
          </template>
        </el-table-column>
        <el-table-column v-if="activeOption.includes('活动分类')" label="活动分类" width="120" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.activeid }} 抽奖</span>
          </template>
        </el-table-column>
        <el-table-column v-if="activeOption.includes('活动名称')" label="活动名称" prop="name" width="200" align="center"/>
        <el-table-column v-if="activeOption.includes('活动编号')" label="活动编号" prop="name" width="100" align="center"/>
        <el-table-column v-if="activeOption.includes('活动时间')" label="活动时间" prop="time" width="200" align="center"/>
        <el-table-column v-if="activeOption.includes('全部状态')" label="全部状态" align="center">
          <template slot-scope="scope">
            <el-tag type="success" class="tag_success">{{ scope.row.status }}进行中</el-tag>
            <!-- <el-tag type="danger" class="tag_danger">已结束</el-tag>
            <el-tag type="info" class="tag_info">未发布</el-tag>
            <el-tag type="warning" class="tag_warning">已结束</el-tag> -->
          </template>
        </el-table-column>
        <el-table-column v-if="activeOption.includes('参与人数/最大限制')" label="参与人数/最大限制" width="150" align="center">
          <template slot-scope="scope">
            <span>1/50{{ scope.row.status }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="activeOption.includes('奖品/商品详情')" label="奖品/商品详情" width="150" align="center">
          <template slot-scope="scope">
            <span>详情{{ scope.row.status }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="activeOption.includes('智能防刷')" label="智能防刷" align="center">
          <template slot-scope="scope">
            <span>已开启{{ scope.row.status }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="activeOption.includes('创建时间')" label="创建时间" align="center" width="160">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="activeOption.includes('创建人')" label="创建人" align="center">
          <template slot-scope="scope">
            <span>张三</span>
          </template>
        </el-table-column>
        <el-table-column prop="created_at" label="操作" width="350"  fixed="right" align="center">
          <template slot-scope="scope">
            <div class="flex btnflex">
               <div class="commhover btn_green mr_10 c_fff" @click="handleFabu(scope.row)">
                <svg-icon icon-class="fabu"  class-name="f-14" /> 发布
              </div>
              <div class="commhover btn_yellow mr_10 c_fff" @click="handleReDistribute(scope.row)">
                <i class="el-icon-edit-outline f-14"></i>编辑
              </div>
              <div class="commhover btn_blue mr_10 c_fff" @click="handleDetail(scope.row)" >
                <svg-icon icon-class="yulan"  class-name="f-14" />预览 
              </div>
              <div class="commhover btn_green mr_10 c_fff" @click="handleDetele(scope.row)" > 
                <i class="el-icon-delete f-14"></i> 删除
              </div>
              <div class="commhover btn_blue mr_10 c_fff" @click="handleLog(scope.row)" >
                <svg-icon icon-class="rizhi"  class-name="f-14" />日志 
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.page"
        :limit.sync="queryParams.num"
        @pagination="getList"
      />

      <el-dialog
        title="确认发布"
        :visible.sync="dialogVisible"
        width="680px"
        class="dialogheaderbg"
        :before-close="handleClose">
        <fabu-comp @close='handleClose'/>
      </el-dialog>

      <!-- 日志 -->
      <el-dialog
        class="dialogheaderbg"
        title="访问日志"
        :visible.sync="dialoglogVisible"
        width="80%"
        :before-close="handleLogClose">
        <log-table :rowId='rowId' @close='handleLogClose'/>
      </el-dialog>

      <!-- 预览 -->
      <el-dialog
        title=""
        :visible.sync="dialogView"
        width="1000px"
        :show-close='false'
        class="noheaderdia"
        :before-close="handleViewClose">
        <view-comp :rowId='rowId' @close='handleViewClose' />
      </el-dialog>
  </div>
</template>
<script>
import { mapState } from 'vuex';
import FabuComp from './components/FabuComp.vue'
import LogTable from './components/LogTable.vue'
import ViewComp from './components/ViewComp.vue'

export default {
  data() {
    return {
      queryParams: {
        page: 1,
        num: 10,
        name: undefined,
      },
      total:1,
      loading:false,
      list:[{id:1},{id:2}],
      checkedOption:[],
      isrefresh:false,
      selectoptions:[
        {id:1,label:"平台"},
        {id:3,label:"活动分类"},
        {id:4,label:"活动名称"},
        {id:5,label:"活动编号"},
        {id:6,label:"活动时间"},
        {id:7,label:"全部状态"},
        {id:8,label:"参与人数/最大限制"},
        {id:9,label:'奖品/商品详情'},
        {id:10,label:"智能防刷"},
        {id:11,label:"创建时间"},
        {id:12,label:"创建人"}
      ],
      dialogVisible:false,

      // 日志
      dialoglogVisible:false,
      rowId:'',

      // 预览
      dialogView:false
    };
  },

  props:{
    type:{
      type:Number,
      default:1
    }
  },

  components:{
    FabuComp,
    LogTable,
    ViewComp
  },

  computed:{
    ...mapState({
      activeOption:state => state.paramsoption.activeOption,
    }),
  },

  created(){
    let activeOption = JSON.parse(localStorage.getItem('activeOption'));
    if(activeOption){
      this.changeSelect(activeOption);
    }
    this.checkedOption=this.activeOption;
  },

  methods: {

    getList() {
      this.loading = true;
      let params = { ...this.queryParams };
      //   if(this.queryParams.type=='创建日期' && this.time && this.time.length){
      //     params.startime = this.time[0]
      //     params.endtime = this.time[1]
      //   }
      //   feedbacklist(params).then((response) => {
      //     this.tableData = response.data.list;
      //     this.total = response.data.count;
      //     this.loading = false;
      //   });
      this.isrefresh = false
      this.loading = false;
    },

    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },

    resetQuery() {
      this.isrefresh = true
      this.resetForm("queryForm");
      this.handleQuery();
    },

    changeSelect(arr){
      this.$store.commit('SET_ACTIVEOPTION',arr);
      this.$nextTick(() => { //在数据加载完，重新渲染表格
        this.$refs.tablelayout&&this.$refs.tablelayout.doLayout();
      })
    },

    handleCommand(command) {
      console.log(command);
    },

    handleFabu(row){
      this.dialogVisible = true
    },

    handleClose(){
      this.dialogVisible = false
    },

    handleLog(row){
      this.rowId = row.id
      this.dialoglogVisible = true
    },

    handleLogClose(){
      this.dialoglogVisible = false
    },

    // 预览
    handleDetail(row){
      this.rowId = row.id
      this.dialogView = true
    },

    handleViewClose(){
      this.dialogView = false
    },

    // 删除
    handleDetele(){

    }
    
  },
};
</script>

<style lang="scss" scoped>
.iconbox {
  width: 32px;
  height: 26px;
}
.imgmini{
    width: 40px;
    height: 40px;
    margin: auto;
}
.imgbox{
    width: 120px;
    height: 120px;
}
</style>
<style lang="scss">
.noheaderdia{
  .el-dialog__header{
    padding: 0 !important;
  }
  .el-dialog__body{
    padding: 0 !important;
  }
}
</style>